<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>小说类别管理</title>
<link rel="stylesheet" type="text/css" href="/Fiction20250327/css/query.css" />
	<script type="text/javascript" src="/Fiction20250327/js/jquery-3.2.1.js"></script>
	<script type="text/javascript">
		$(function() {
			var params = new URLSearchParams(window.location.search);
			var pageNo = params.get("pageNo");
			var likeValue = params.get("likeValue");
			selectByPage(pageNo, likeValue);// 调用分页查询方法
			$("#queryByLikeValue").click(function() {
				var str = $("#likeValueStr").val();
				selectByPage(1, str);//当点击查询按钮时，调用分页查询
			})
			//限定当位于首页时,上一页按钮失效
			//当位于尾页时,下一页按钮失效

		});
		// 分页查询
		function selectByPage(pageNo, likeValue) {
			$("#categoryList").empty();
			var url="/Fiction20250327/selectByPage.category";
			var params ={"pageNo":pageNo,"likeValue":likeValue};
			$.post(url,params,function(data){
				if(data==""){
						window.location.href="/Fiction20250327/login.html";
				}
				var JsonObj =JSON.parse(data)
				var  recordList =JsonObj.recordList;
				for (let i = 0; i < recordList.length; i++) {
					var category = recordList[i]
					$("<tr><td>"+category.categoryid+"</td><td>"+category.categoryname+"</td><td>"+category.createtime+"</td><td>"+category.description+"" +
							"</td><td><a href='/Fiction20250327/toEdit.category?categoryid="+category.categoryid+"'>编辑</a></td>" +
							"<td><a href='/Fiction20250327/deleteById.category?categoryid="+category.categoryid+"' onclick='del(this)'>删除</a></td></tr>").appendTo($("#categoryList"))
				}
				//回填查询条件
				$("#likeValueStr").val(JsonObj.likeValue);
				//显示分页相关的信息
				$("#recordCount").text(JsonObj.recordCount);
				$("#totalPages").text(JsonObj.totalPages);
				$("#pageNo").text(JsonObj.pageNo);
				//分页的四个超链接
				$("#homePage").prop("href","/Fiction20250327/toList.category?pageNo=1&likeValue="+JsonObj.likeValue)
				if(parseInt(JsonObj.pageNo)>1)
				$("#priPage").prop("href","/Fiction20250327/toList.category?pageNo="+(parseInt(JsonObj.pageNo) - 1)+"&likeValue="+JsonObj.likeValue)
				if(parseInt(JsonObj.pageNo) < parseInt(JsonObj.totalPages))
				$("#nextPage").prop("href","/Fiction20250327/toList.category?pageNo="+(parseInt(JsonObj.pageNo) + 1)+"&likeValue="+JsonObj.likeValue)
				$("#tailPage").prop("href","/Fiction20250327/toList.category?pageNo="+JsonObj.totalPages+"&likeValue="+JsonObj.likeValue)
			});
			}
		//删除
		function del(aNode){
			var str=$(aNode).parent().parent().find("td").eq(1).text();
			if(! window.confirm("确定要删除"+str+"的信息吗？")){
				event.preventDefault();
			}

		}
	</script>
</head>
<body>
	<div id="top">·当前位置： 类别管理 -- 查看小说类别</div>
	<div id="contexttop">
		<table id="tab" border="1">
			<tr>
				<td colspan="6" height="50px">
						<input type="text" id="likeValueStr" title="类别ID、类别名称、描述" placeholder="类别ID、类别名称、描述"  />
						<input type="button" value="查询" id="queryByLikeValue"/>
				</td>
			</tr>
			<tr bgcolor="#E0FBC4">
				<th>类别ID</th>
				<th>类别名称</th>
				<th>创建时间</th>
				<th>描述</th>
				<th colspan=2>操作</th>
			</tr>
			<tbody id="categoryList"></tbody>

		</table>
	</div>
	<div align="center" id="contextbotton">
		&nbsp;总记录数&nbsp;<span id="recordCount"></span>&nbsp; 条
		&nbsp;共&nbsp;<span id="totalPages"></span>&nbsp;页
		<a href="#" id="homePage">首页</a>
		<a href="#" id="priPage">上一页</a>
		<a href="#" id="nextPage">下一页</a>
		<a href="#" id="tailPage">尾页</a>
		第&nbsp;<span id="pageNo"></span>&nbsp;页
	</div>
</body>
</html>